package com.gm.wj.dao;

import com.gm.wj.entity.JotterArticle;
import com.gm.wj.entity.SysMessage;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysMessageDAO extends JpaRepository<SysMessage,Integer> {

    SysMessage findById(int id);

    // 多条件模糊查询
    @Query(value = "select * from sys_message  where  (?1 is null or receive_username like ?1) and (?2 is null or subject like ?2) " +
            "and (?3 is null or content like ?3) and (?4 is null or is_success = ?4) and (?5 is null or send_type = ?5) ",nativeQuery = true)
    List<SysMessage> find(String queryKey1, String queryKey2, String queryKey3,String queryKey4,String queryKey5);

    // 首页数据统计
    @Query(value = "select count(*) from sys_message where is_success = 1",nativeQuery = true)
    int findMessageData();

    // 首页数据统计
    @Query(value = "select count(*) from sys_message where is_success = 1 and send_type = 0",nativeQuery = true)
    int findMessageDataByphone();

    // 首页数据统计
    @Query(value = "select count(*) from sys_message where is_success = 1 and send_type = 1",nativeQuery = true)
    int findMessageDataByemail();

    // jpa分页查询  多条件
    Page<SysMessage> findAll(Specification<SysMessage> specification, Pageable pageable);
}
